<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model :model="model" :form="form" :rules="rules" ref="form" layout="vertical">
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="日期" prop="time">
<!--              <a-input placeholder="请输入" v-model="model.time" style="width: 100%" />-->
              <a-date-picker v-model:value="time" placeholder="选择日期" style="width:100%" :allowClear="false"
                             @change="changeTime"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="车间" prop="workshop">
              <j-dict-select-tag placeholder="请选择车间" v-model="model.workshop" dictCode="workshop"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="班次" prop="classes">
              <j-dict-select-tag placeholder="请选择班次" v-model="model.classes" dictCode="shift"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="上班时间" prop="workHours">
              <a-input-number placeholder="请输入" v-model="model.workHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="机台时间" prop="machineHours">
              <a-input-number placeholder="请输入" v-model="model.machineHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机号" prop="machine">
              <a-input placeholder="请输入" v-model="model.deviceNo" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="工号" prop="workNoBlockingCar">
              <a-input placeholder="请输入" v-model="model.workNo" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="姓名" prop="nameBlockingCar">
              <a-input placeholder="请输入" v-model="model.realname" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="型号" prop="machineHours">
              <a-input placeholder="请输入" v-model="model.model" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台分类（自络、托盘）" prop="machine">
              <a-input placeholder="请输入" v-model="model.machineClassification" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="品种类别" prop="productCategory">
              <a-input placeholder="请输入" v-model="model.productCategory" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="品种" prop="productType">
              <j-dict-select-tag placeholder="请选择品种" v-model="model.productType" style="width: 100%" dictCode="crm_product_type_spooling,product_type,id" @change="changeProductType"/>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="支数" prop="productBranch">
              <a-input placeholder="请输入" v-model="model.productBranch" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台系数" prop="machineCoefficient">
              <a-input placeholder="请输入" v-model="model.machineCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="品种系数" prop="productTypeCoefficient">
              <a-input placeholder="请输入" v-model="model.productTypeCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="单价系数" prop="unitPriceCoefficient">
              <a-input placeholder="请输入" v-model="model.unitPriceCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="综合系数" prop="comprehensiveCoefficient">
              <a-input placeholder="请输入" v-model="model.comprehensiveCoefficient" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="锭数" prop="ingots">
              <a-input placeholder="请输入" v-model="model.ingots" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="8小时定额产量" prop="fixedOutputEightHours">
              <a-input placeholder="请输入" v-model="model.fixedOutputEightHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="台数" prop="machinesNum">
              <a-input placeholder="请输入" v-model="model.machinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="台数(8小时)" prop="machinesNumEightHours">
              <a-input placeholder="请输入" v-model="model.machinesNumEightHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="定额看台（台）" prop="fixedMachinesNum">
              <a-input placeholder="请输入" v-model="model.fixedMachinesNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="总看台率%" prop="totalMachinesRate">
              <a-input placeholder="请输入" v-model="model.totalMachinesRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台产量（kg/台）" prop="machinesOutput">
              <a-input placeholder="请输入" v-model="model.machinesOutput" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="工资产量 （kg/台）" prop="wagesOutput">
              <a-input placeholder="请输入" v-model="model.wagesOutput" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="扩台" prop="expansionMachines">
              <a-input placeholder="请输入" v-model="model.expansionMachines" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="换管盒数量" prop="changeTubeBoxNum">
              <a-input placeholder="请输入" v-model="model.changeTubeBoxNum" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="换管盒数星(8小时)" prop="changeTubeBoxNumEightHours">
              <a-input placeholder="请输入" v-model="model.changeTubeBoxNumEightHours" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="产量单价（kg/台）" prop="outputPrice">
              <a-input placeholder="请输入" v-model="model.outputPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="换管盒单价" prop="changeTubeBoxPrice">
              <a-input placeholder="请输入" v-model="model.changeTubeBoxPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="换管盒工资" prop="changeTubeBoxWages">
              <a-input placeholder="请输入" v-model="model.changeTubeBoxWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="产量工资（元/台）" prop="outputWages">
              <a-input placeholder="请输入" v-model="model.outputWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="锭数补贴（元/台）" prop="ingotsNumSubsidies">
              <a-input placeholder="请输入" v-model="model.ingotsNumSubsidies" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="系数补扣" prop="coefficientDeduction">
              <a-input placeholder="请输入" v-model="model.coefficientDeduction" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="其它补贴" prop="otherSubsidies">
              <a-input placeholder="请输入" v-model="model.otherSubsidies" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="合计工资" prop="totalWages">
              <a-input placeholder="请输入" v-model="model.totalWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="完成率%" prop="completionRate">
              <a-input placeholder="请输入" v-model="model.completionRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="机台保养" prop="machinesMaintenance">
              <a-input placeholder="请输入" v-model="model.machinesMaintenance" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="备注" prop="remark">
              <a-input placeholder="请输入" v-model="model.remark" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="单台看台率" prop="selfSpoolingFixedMachinesRate">
              <a-input placeholder="请输入" v-model="model.selfSpoolingFixedMachinesRate" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="上班时间" prop="workingTime">
              <a-input placeholder="请输入" v-model="model.workingTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="看台" prop="manageMachines">
              <a-input placeholder="请输入" v-model="model.manageMachines" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="台车时间" prop="machinesCarTime">
              <a-input placeholder="请输入" v-model="model.machinesCarTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="台车天时间" prop="machinesCarDayTime">
              <a-input placeholder="请输入" v-model="model.machinesCarDayTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="工号转换" prop="workIdConversion">
              <a-input placeholder="请输入" v-model="model.workIdConversion" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="原单价" prop="originalPrice">
              <a-input placeholder="请输入" v-model="model.originalPrice" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="原工资" prop="originalWages">
              <a-input placeholder="请输入" v-model="model.originalWages" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="6">
            <a-form-model-item label="现-原" prop="originalNow">
              <a-input placeholder="请输入" v-model="model.originalNow" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="16">
          <a-col :span="6">
            <a-form-model-item label="幅度" prop="rangeData">
              <a-input placeholder="请输入" v-model="model.rangeData" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import JEditor from '@/components/jeecg/JEditor'
import JSwitch from '@/components/jeecg/JSwitch'

import moment from 'moment'
import { getShiftSystem, productTypeSpoolingList, productTypeSpunYarn } from '../../../../api/customApi'
export default {
  name: 'DeviceModal',
  components: {
    JEditor,
    JSwitch,
  },
  props:{
    planTime: String,
  },
  data() {
    return {
      title: '操作',
      visible: false,
      time: null,
      workHours: null,
      machineHours: null,
      disable: true,
      model: {
        planTime:'',
        workshop:null,
        classes:null,
        workHours:'',
        machineHours:'',
        deviceNo:'',
        workNo:'',
        realname :'',
        machineClassification :'',
        model :'',
        productCategory:'',
        productType:null,
        productBranch:'',
        machineCoefficient:'',
        productTypeCoefficient:'',
        unitPriceCoefficient:'',
        comprehensiveCoefficient:'',
        ingots:'',
        fixedOutputEightHours:'',
        machinesNum:'',
        machinesNumEightHours:'',
        fixedMachinesNum:'',
        totalMachinesRate:'',
        machinesOutput:'',
        wagesOutput:'',
        expansionMachines:'',
        changeTubeBoxNum:'',
        changeTubeBoxNumEightHours:'',
        outputPrice:'',
        changeTubeBoxPrice:'',
        changeTubeBoxWages:'',
        outputWages:'',
        ingotsNumSubsidies:'',
        coefficientDeduction:'',
        otherSubsidies:'',
        totalWages:'',
        completionRate:'',
        machinesMaintenance:'',
        remark:'',
        selfSpoolingFixedMachinesRate:'',
        workingTime:'',
        manageMachines:'',
        machinesCarTime:'',
        machinesCarDayTime:'',
        workIdConversion:'',
        originalPrice:'',
        originalWages:'',
        originalNow:'',
        rangeData:'',
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      url: {
        add: '/crm_salary_excel_spooling/crmSalaryExcelSpooling/add',
        edit: '/crm_salary_excel_spooling/crmSalaryExcelSpooling/edit',
      },
    }
  },
  created() {},
  methods: {
    changeWorkHours(date, dateString){
      this.model.workHours = dateString + " 00:00:00"
      // this.model.workHours = new Date(dateString).getTime()
    },
    changeMachineHours(date, dateString){
      this.model.machineHours = dateString + " 00:00:00"
      // this.model.machineHours = new Date(dateString).getTime()
    },
    changeProductType(val){
      productTypeSpoolingList({ id:val }).then((res) => {
        // this.model = res.result.records[0]
        this.model.productCategory = res.result.records[0].productCategory
        this.model.productBranch = res.result.records[0].productBranch
        this.model.machineCoefficient = res.result.records[0].machineCoefficient
        this.model.productTypeCoefficient = res.result.records[0].productTypeCoefficient
        this.model.unitPriceCoefficient = res.result.records[0].unitPriceCoefficient
        this.model.ingots = res.result.records[0].ingots
        this.model.fixedMachinesNum = res.result.records[0].fixedMachinesNum
        this.model.outputPrice = res.result.records[0].outputPrice
        this.model.changeTubeBoxPrice = res.result.records[0].changeTubeBoxPrice
        this.model.originalPrice = res.result.records[0].originalPrice
      })
    },
    changeTime(date, dateString){
      this.model.planTime = dateString
    },
    add() {
      this.disable = false
      this.model.planTime = this.planTime
      this.time = this.planTime
      this.edit({}, 1)
    },
    edit(record, isEdit) {
      if (isEdit != 1) {
        this.model = Object.assign({}, record)
        this.time = moment(this.model.planTime)
      }

      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.disable = true
      this.$refs.form.resetFields();
      this.model.planTime= ''
      this.model.workshop = null
      this.model.classes = null
      this.model.workHours= ''
      this.model.machineHours= ''
      this.model.deviceNo= ''
      this.model.workNo= ''
      this.model.realname = ''
      this.model.machineClassification = ''
      this.model.model = ''
      this.model.productCategory= ''
      this.model.productType = null
      this.model.productBranch= ''
      this.model.machineCoefficient= ''
      this.model.productTypeCoefficient= ''
      this.model.unitPriceCoefficient= ''
      this.model.comprehensiveCoefficient= ''
      this.model.ingots= ''
      this.model.fixedOutputEightHours= ''
      this.model.machinesNum= ''
      this.model.machinesNumEightHours= ''
      this.model.fixedMachinesNum= ''
      this.model.totalMachinesRate= ''
      this.model.machinesOutput= ''
      this.model.wagesOutput= ''
      this.model.expansionMachines= ''
      this.model.changeTubeBoxNum= ''
      this.model.changeTubeBoxNumEightHours= ''
      this.model.outputPrice= ''
      this.model.changeTubeBoxPrice= ''
      this.model.changeTubeBoxWages= ''
      this.model.outputWages= ''
      this.model.ingotsNumSubsidies= ''
      this.model.coefficientDeduction= ''
      this.model.otherSubsidies= ''
      this.model.totalWages= ''
      this.model.completionRate= ''
      this.model.machinesMaintenance= ''
      this.model.remark= ''
      this.model.selfSpoolingFixedMachinesRate= ''
      this.model.workingTime= ''
      this.model.manageMachines= ''
      this.model.machinesCarTime= ''
      this.model.machinesCarDayTime= ''
      this.model.workIdConversion= ''
      this.model.originalPrice= ''
      this.model.originalWages= ''
      this.model.originalNow= ''
      this.model.rangeData= ''
    },

    handleOk() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model)
          console.log('formData', formData)
          //时间格式化
          httpAction(httpurl, formData, method)
            .then((res) => {
              if (res.success) {
                this.$message.success(res.message != null ? res.message : '执行成功')
                this.$emit('ok')
              } else {
                this.$message.warning(res.message != null ? res.message : '执行失败')
              }
            })
            .finally(() => {
              this.confirmLoading = false
              this.close()
            })
        } else {
          return false
        }
      })
    },

    handleCancel() {
      this.close()
    },
  },
}
</script>

<style scoped>

</style>